﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using ExtBusiness.Admin;
using WF_Business;
using ExtBusiness.FlowOperation;

public partial class Xnjc_department_assess : PageBase
{
    public string displayType =string.Empty;
    public string wname = string.Empty;
    public string orderID = string.Empty;
    public string orderBy = string.Empty;
    public string timeFromOfAccept = string.Empty;
    public string timeToOfAccept = string.Empty;
    public double secondsPerDay;
    public ArrayList alWorkStatus = null;
    protected string strhtml = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
         displayType = Request["displayType"];
         wname = Request["wname"];
         orderID = Request["orderID"];
         orderBy = Request["orderBy"];
         timeFromOfAccept = Request["timeFromOfAccept"];
         timeToOfAccept = Request["timeToOfAccept"];

        ClsWorkFlow clsWorkFlow = new ClsWorkFlow();



        if (!string.IsNullOrEmpty(wname) && !string.IsNullOrEmpty(orderID))
        {
            alWorkStatus = clsWorkFlow.WorkStatusOfStepAndDepartment(wname, orderID, timeFromOfAccept,
                timeToOfAccept, orderBy);
        }

        //获取每天工作时间
         secondsPerDay = ExtBusiness.SystemConfig.WorkHoursInEveryDay;


         if (!"hist.userid".Equals(orderBy))
         {
             string lastStepName = null;

             for (int i = 0; i < alWorkStatus.Count; i++)
             {
                 Dictionary<string, string> m =(Dictionary<string, string>)alWorkStatus[i];

                 string stepName = m["STEP"];
                 if (stepName.Equals(lastStepName))
                 {
                     stepName = string.Empty;
                 }
                 else
                 {
                     lastStepName = stepName;
                 }
                 string sql = (string)m["detailSql"];

                 strhtml += "  <tr><td width='20%'>" + stepName +
                 "  </td><td>" + m["USER_NAME"] + "   </td>   <td>" + m["CNT"] + " </td>  <td>";

                 string totalTimeStr = m["TOTAL_TIME"];
                 long totalTime = 0;
                 if (!string.IsNullOrEmpty(totalTimeStr))
                 {
                     totalTime = Int64.Parse(totalTimeStr);
                 }
                 string cntStr = m["CNT"];
                 int cnt = Int32.Parse(cntStr);
                 if (cnt != 0)
                 {
                     strhtml += ClsWorkDaySet.ToDefaultTime(totalTime / cnt);
                 }
                 Session["querySql"] = sql;

                 strhtml += " </td> <td> <a href='../QueryAndCollect/TaskQueryInstance.aspx' >详细</a></td>  </tr>";
             }

         }
         else 
         {
                string lastUserName = null;

            for (int i = 0; i < alWorkStatus.Count; i++)
            {
                Dictionary<string, string> m =(Dictionary<string, string>)alWorkStatus[i];

                string userName = m["USER_NAME"];
                if (userName.Equals(lastUserName))
                {
                    userName = string.Empty; ;
                }
                else
                {
                    lastUserName = userName;
                }
                string sql = m["detailSql"];
				
        strhtml+="  <tr> <td>"+userName+" </td> <td>"+m["STEP"]+"  </td> <td>"+m["CNT"]+
            "</td>  <td>";
                
                    string totalTimeStr = m["TOTAL_TIME"];
                    long totalTime = 0;
                    if (!string.IsNullOrEmpty(totalTimeStr))
                    {
                        totalTime = Int64.Parse(totalTimeStr);
                    }
                    string cntStr = m["CNT"];
                    int cnt = Int32.Parse(cntStr);

                    if (cnt != 0)
                    {
                        string strResult = ClsWorkDaySet.ToDefaultTime(totalTime / cnt);
                        strhtml+=strResult;
                    }

                    Session["querySql"] = sql;
                    strhtml += " </td>  <td>   <a href='../QueryAndCollect/TaskQueryInstance.aspx'>详细</a></td></tr>";
            }
         }
    }
}
